import { getOldsterStatus, pageQueryOld, addOldReq, updateOldReq, logicDeleteOldById, logicBatchDeleteOldByIds } from '@/api/admin/common'
// import { message, messageType } from '@/utils/message'
const state = {
    oldRespData: [],
    oldTotal: 0,
    oldsterStatus: [],
};
const mutations = {

    // 分页查询老人信息
    pageQueryOldMutations(state, param) {
        state.oldRespData = param.data;
        state.oldTotal = param.total;
    },

    oldsterStatusMutations(state, param) {
        state.oldsterStatus = param.data
    }
};
const actions = {
    // 分页查询老人信息
    async pageQueryOldListActions(context, page) {
        await pageQueryOld(page).then(resp => {
            if (!resp) return;
            console.log('老人-》', resp.data);
            context.commit('pageQueryOldMutations', resp.data)
        }, error => {
            console.log(error);
        })
    },

    // 添加老人信息
    async addOldActions(context, form) {
        await addOldReq(form).then(resp => {
            if (!resp) return;
        }, error => {
            console.log(error);
        })
    },

    // 修改老人信息
    async updateOldActions(context, form) {
        await updateOldReq(form).then(resp => {
            if (!resp) return;
            console.log(resp);

        }, error => {
            console.log(error);
        })
    },

    // 逻辑删除老人信息
    async logicDeleteOldByIdActions(context, id) {
        await logicDeleteOldById(id).then(resp => {
            if (!resp) return;
            console.log(resp);
        }, error => {
            console.log(error);
        })
    },

    // 批量逻辑删除老人信息
    async logicBatchDeleteOldByIdsActions(context, ids) {
        await logicBatchDeleteOldByIds(ids).then(resp => {
            if (!resp) return;
            console.log(resp);
        }, error => {
            console.log(error);
        })
    },

    // 获取老人社会状态
    async oldsterStatusActions(context) {
        await getOldsterStatus().then(resp => {
            console.log(resp, context);
            if (!resp) return;
            context.commit('oldsterStatusMutations', resp.data)
        }, error => {
            console.log(error);

        })
    }
};

export default {
    namespaced: true,
    state,
    mutations,
    actions,
}